<?php
namespace App\Http\Controllers\Home;

use App\Models\Agent;
use App\Models\Goods;

Class GoodsController extends BaseController{

    public function __construct(Goods $goods,Agent $agent){
        parent::__construct();
        $this->goods = $goods;
        $this->agent = $agent;
    }

    public function getIndex(){
        $rows = $this->goods->getGoodsList(request());
//        dd($rows);
        return view('home.goods',compact('rows'));
    }

    /**
     * 判断该手机号是否存在
     */
    public function isExistsMobile(){
          $mobile = $_GET['mobile'];
          /**
           *  验证手机格式是否正确
           */
        $telReg = "/^1[3|4|5|7|8][0-9]{9}$/";
        if (!preg_match($telReg, $mobile, $arr)) {
            $res = ['status' => 0, 'msg' => "手机号格式不正确"];
            echo json_encode($res);
        }
        // 判断该手机号是否存在数据库
        $condition['mobile'] = $mobile;
        $brand = $this->agent->getOne($condition);
        if ($brand) {
            $res = ['status' => 200, 'msg' => "手机号验证通过"];
        }else{
            $res = ['status' => 400, 'msg' => "该手机号不存在"];
        }
        echo json_encode($res);
    }
}